package com.haonan.controller;

import com.haonan.pojo.dto.EmpDTO;
import com.haonan.pojo.dto.EmpQueryParamDTO;
import com.haonan.pojo.entily.Emp;
import com.haonan.pojo.vo.PageResult;
import com.haonan.pojo.entily.Result;
import com.haonan.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    //分页查询员工信息
    @GetMapping
    public Result findAll( EmpQueryParamDTO empQueryParamDTO){
        PageResult<Emp> pageResult = empService.findAll(empQueryParamDTO);
        return Result.success(pageResult);
    }

    //删除员工信息
    @DeleteMapping
    public Result deleteById(@RequestParam("ids") List<Integer> ids){
        empService.deleteById(ids);
        return Result.success();
    }

    //添加员工信息
    @PostMapping
    public Result save(@RequestBody EmpDTO empDTO){
        empService.save(empDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Emp emp=empService.findById(id);
        return Result.success(emp);
    }
    @PutMapping
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();
    }

    @GetMapping("/list")
    public Result findAll(){
        List<Emp> list=empService.find();
        return Result.success(list);
    }


}
